/*
 
对于1的个数为k的32位int（二进制表示）
求其中第j大的数？

*/
#include "junix.h"

uint32_t Cmn(uint32_t m, uint32_t n) {
	uint32_t p=1,q=1;
	for (uint32_t i=0;i<n;i++) {
		p *= m-i;
		q *= n-i;
	}
	return p/q;
}

/*
uint32_t f(uint32_t m, uint32_t n) {
	uint32_t nth = 1;
	uint32_t bits[33]={0};
	std::fill_n(bits+1,m,1);

	while (nth<n) {
		int i=0;
		for (i=1;i<=32;i++) 
			if (bits[i]==0 && bits[i-1]==1) 
				break;

		std::swap(bits[i],bits[i-1]);
		++ nth;
		if (nth == n)
			break;
	}

	uint32_t value = 0;
	for (int i=32;i>0;i--)
		value = ((value<<1)|bits[i]);

	return value;
}
*/

/*
uint32_t f(uint32_t m,uint32_t n) {
	typedef std::vector<std::vector<uint32_t> > MATRIX;
	MATRIX matrix(33,std::vector<uint32_t>(33,0));
	int bits[33] = {0};

	for (int i=1;i<=32;i++)
		for (int j=1;i<=i;j++) 
			matrix[i][j] = Cmn(i,j);

	uint32_t max_pos = m;
	for (uint32_t i=m;i++;i<=32) {
		if (matrix[i-1][m-1]>=n) {
			max_pos  = i;
			bits[max_pos]=1;
			break;
		}
	}

	uint32_t count_left = n;
	uint32_t pos_left = m-1;

	for ( uint32_t i=max_pos-1;
		  i>0 && pos_left>0;
		  i--) 
	{
		if (matrix[i-1][pos_left]<count_left) {
			bits[i]=1;
			-- pos_left;
			count_left -= 
		}
	}
}
*/

int main(){
	//std::cout<<Cmn(4,2)<<std::endl;
	std::cout<<f(5,1)<<std::endl;
}
